package com.zenagro.actions;

import java.io.*;
import java.util.*;

import org.openxava.actions.*;
import org.openxava.model.*;
import org.openxava.util.*;
import org.openxava.validators.*;

import com.sun.org.apache.xml.internal.serializer.utils.*;
import com.zenagro.utils.*;

public class DeleteCustomSelectedAction extends TabBaseAction implements IModelAction {
	
private String model;
	
public void execute() throws Exception {				
	Map [] selectedOnes = getSelectedKeys(); 
	if (selectedOnes != null) {						
		for (int i = 0; i < selectedOnes.length; i++) {				
			Map key = selectedOnes[i];
			try {									
				MapFacade.remove(model, key);
				Files.deleteDir(FileEntityUtils.pathRepo+File.separator+this.getModelName()+File.separator+key.get("id"));
			}
			catch (ValidationException ex) {
				addError("no_delete_row", new Integer(i), key);
				addErrors(ex.getErrors());
			}								
			catch (Exception ex) { 
				addError("no_delete_row", new Integer(i), key);
								}						
		}
		getTab().deselectAll();
		resetDescriptionsCache();
	}
}

public void setModel(String modelName) {
	this.model = modelName;		
}

}
